<!--
 * @Author: early-autumn
 * @Date: 2020-05-04 09:35:24
 * @LastEditors: early-autumn
 * @LastEditTime: 2020-06-01 13:05:51
 -->
<template>
  <div v-if="show">
    <slot />
  </div>
</template>
<script>
import { DEFAULT_NAME, getId, getValues } from './util'
import event from './event'

export default {
  name: 'ColumnsFilterView',
  props: {
    // 名称
    name: {
      type: String,
      default: DEFAULT_NAME,
    },
  },
  data() {
    return {
      id: '',
      show: true,
      ident: '',
    }
  },
  created() {
    this.id = getId(this.name)
    event.on(this.id, (e) => this.update(e))
  },
  mounted() {
    const children = this.$children[0]
    const values = getValues(this.id)
    this.ident = children.label || children.type
    this.update(values)
  },
  methods: {
    update(columns) {
      this.show = columns === null || columns.indexOf(this.ident) !== -1
    },
  },
}
</script>
